package exercise;

import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 * @classname:NuberFormatterDemo
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/10 11:49
 * @version: 0.1
 * @since:1.8
 */
public class NuberFormatterDemo {
    public static void main(String[] args) {
        //保留两位小数
        String PATTERN = ".##";
        double num = 123.343434;
        //实现子类DecimalFormat
        NumberFormat numberFormat = new DecimalFormat(PATTERN);
        String format = numberFormat.format(num);
        System.out.println(format);

        //自动百分比并保留两位小数
        String Pattern = "#.##%";
        double num1 = 0.2232;
        NumberFormat numberFormat1 = new DecimalFormat(Pattern);
        String format1 = numberFormat1.format(num1);
        System.out.println(format1);

        //每三位以逗号隔开
        String Patt = ",###.##";
        double num2  = 234321321.213;
        NumberFormat numberFormat2 = new DecimalFormat(Patt);
        String format2 = numberFormat2.format(num2);
        System.out.println(format2);

    }
}
